package model

import "math"

// RadarGrid defines the radar grid structure
type RadarGrid struct {
	Lat      float64
	Lon      float64
	Altitude float64
}

// GetGridLatLon calculate grid lat, lon and altitude
func (r *RadarGrid) GetGridLatLon(center RadarCenter, gridIndex int, azimuth float64, sensorHeight float64, elevation float64) {
	dist := float64(gridIndex) * center.BinLen

	lonIncr := dist * math.Sin(azimuth/100)
	latIncr := dist * math.Cos(azimuth/100)
	r.Lon = center.Lon + azimuthIncr(lonIncr)
	r.Lat = center.Lat + azimuthIncr(latIncr)
	r.Altitude = sensorHeight + dist*math.Sin(elevation) + math.Pow(dist, 2)/(2*8500000)
}

func azimuthIncr(incr float64) float64 {
	radius := float64(6378100)
	radian := incr / radius
	return radian * 180 / math.Pi
}
